package com.kaishengit.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.IdeaComment;
import com.kaishengit.entity.User;
import com.kaishengit.service.IdeaCommentService;
import com.kaishengit.util.String.DateTimeUtil;
import com.kaishengit.util.web.ServletUtil;

public class SaveIdeaComment extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String id = request.getParameter("id");
		String content = request.getParameter("text");
		IdeaComment ideaComment = new IdeaComment();
		ideaComment.setContent(content);
		ideaComment.setCreatetime(DateTimeUtil.getNow());
		ideaComment.setUserId(((User)request.getSession().getAttribute("user")).getId());
		ideaComment.setIdeaId(Integer.parseInt(id));
		
		new IdeaCommentService().save(ideaComment);
		
		ServletUtil.redirect(response, "ideaShow.jspx?id="+Integer.parseInt(id));
	}
}
